<?php

class EmployeController extends Zend_Controller_Action
{

    public function init()
    {
       $this->view->addHelperPath(
		'ZendX/JQuery/View/Helper', 
		'ZendX_JQuery_View_Helper');
    }

    public function indexAction()
    {
        // action body
    }
    
public function addAction()
	{
		$form = new Application_Form_Employe();
		$envoyer = new Zend_Form_Element_Submit('envoyer');
		$envoyer->setAttrib('id', 'boutonenvoyer');
		$form->addElements(array($envoyer));
		$form->envoyer->setLabel('Ajouter');
		$this->view->form = $form;

		if ($this->getRequest()->isPost()) {
			$formData = $this->getRequest()->getPost();
			if ($form->isValid($formData)) {
					
				$civilite=$form->getValue('civilite');
				$nom=strtoupper($form->getValue('nom'));
				$prenom=ucfirst($form->getValue('prenom'));
				$fonction=strtolower($form->getValue('fonction'));
				$telephone=$form->getValue('telephone');
				$email=$form->getValue('email');
				$situation = $form->getValue('situation');

				$employes = new Application_Model_DbTable_Employes();
				$employes->addEmploye($civilite, $nom, $prenom, $fonction, $telephone, $email, $situation);

				$this->_helper->redirector('index');
			} else {
				$form->populate($formData);
			}
		}
	}
	
	
public function updateAction()
	{
		$form = new Application_Form_Employe();
		$envoyer = new Zend_Form_Element_Submit('envoyer');
		$envoyer->setAttrib('id', 'boutonenvoyer');
		$form->addElements(array($envoyer));
		$form->envoyer->setLabel('Mettre a jour');
		$this->view->form = $form;

		if ($this->getRequest()->isPost()) {
			$formData = $this->getRequest()->getPost();
			if ($form->isValid($formData)) {
				$id= $form->getValue('id');
				$civilite=$form->getValue('civilite');
				$nom=strtoupper($form->getValue('nom'));
				$prenom=ucfirst($form->getValue('prenom'));
				$fonction=strtolower($form->getValue('fonction'));
				$telephone=$form->getValue('telephone');
				$email=$form->getValue('email');
				$situation = $form->getValue('situation');
				$employes = new Application_Model_DbTable_Employes();
				$employes->updateEmploye($id, $civilite, $nom, $prenom, $fonction, $telephone, $email,$situation);
				
				$this->_helper->redirector('list');
				
			} else {
				$form->populate($formData);
			}
		} else {
			$id = $this->_getParam('id', 0);
			if ($id > 0) {
				$employes = new Application_Model_DbTable_Employes();
				$form->populate($employes->getEmploye($id));
			}
		}


	}
	
public function listAction()
	{
		
		$employe = new Application_Model_DbTable_Employes();
		$listEmploye= $employe->listCurrentEmploye();
		$nb=sizeof($listEmploye);
		


		$this->view->list = $listEmploye;



	}


}

